//
//  JoinProjectTableViewCell.m
//  WideHelp
//
//  Created by ENERGY on 2018/8/7.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "JoinProjectTableViewCell.h"


@interface JoinProjectTableViewCell()
@property (nonatomic, strong)UILabel * titleLab;
@end
@implementation JoinProjectTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor whiteColor];
        __weak typeof (self)weakSelf = self;
        [self.contentView addSubview:self.titleLab];
        [self.contentView addSubview:self.nameTextField];
        [self.contentView addSubview:self.arrowBtn];
        [self.contentView addSubview:self.coverBtn];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView.mas_left).mas_offset(17/WIDTH_6_SCALE);
            make.top.equalTo(weakSelf.contentView);
            make.bottom.equalTo(weakSelf.contentView.mas_bottom).mas_offset(-1/WIDTH_6_SCALE);
        }];
        [self.nameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.titleLab.mas_right).mas_offset(15/WIDTH_6_SCALE);
            make.top.height.equalTo(weakSelf.titleLab);
        }];
        [self.arrowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView.mas_right).mas_offset(-24/WIDTH_6_SCALE);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.height.mas_equalTo(6/WIDTH_6_SCALE);
            make.width.mas_equalTo(12/WIDTH_6_SCALE);
        }];
        [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView.mas_right);
            make.centerY.equalTo(weakSelf.contentView.mas_centerY);
            make.top.equalTo(weakSelf.contentView.mas_top);
            make.left.equalTo(weakSelf.arrowBtn.mas_left);
        }];
        UIView * lineView = [[UIView alloc] init];
        lineView.backgroundColor = getColor(@"eeeeee");
        [self.contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.left.right.equalTo(weakSelf.contentView);
            make.height.mas_equalTo(1/WIDTH_6_SCALE);
        }];
    }return self;
}
-  (UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.font = DEF_FontSize_14;
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.textAlignment = NSTextAlignmentLeft;
    }return _titleLab;
}

- (UITextField *)nameTextField{
    if (!_nameTextField) {
        _nameTextField = [[UITextField alloc] init];
        _nameTextField.font = DEF_FontSize_14;
        _nameTextField.textColor = [UIColor blackColor];
        _nameTextField.textAlignment = NSTextAlignmentLeft;
    }return _nameTextField;
}

-  (UIButton *)arrowBtn{
    if (!_arrowBtn) {
        _arrowBtn = [[UIButton alloc] init];
        [_arrowBtn setBackgroundImage:[UIImage imageNamed:@"down_icon"] forState:UIControlStateNormal];
    }
    return _arrowBtn;
}
-  (UIButton *)coverBtn{
    if (!_coverBtn) {
        _coverBtn = [[UIButton alloc] init];
        [_coverBtn addTarget:self action:@selector(coverBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _coverBtn;
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.titleLab.text = model[@"title"];
    self.nameTextField.placeholder = model[@"placeHolder"];
}
#pragma mark - action
- (void)coverBtnClick:(UIButton *)sender{
    if (self.getChooseViewBlock) {
        self.getChooseViewBlock();
    }
}
@end
